import { getToken, upload } from '@/api/uploadQN'





export const uploadFileByQN = async (file: File, key: string, token: string = '') => {

  const formdata = new FormData()
  formdata.append('file', file)
  formdata.append('key', key)


  if (token) {
    formdata.append('token', token)
  } else {

    const { data: { token, code } } = await getToken()

    // console.log(token)
    // console.log(code)

    if (code === 0) {
      formdata.append('token', token)
    } else {
      return Promise.reject('获取token失败')
    }


  }

  return upload(formdata)

}
